﻿using System;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Xml;

using Aulac.Srv.Db.Provider; using Aulac.Srv.Db.Connect;
using System.Collections.Generic;
using Aulac.Rsc.Ems; using Aulac.Rsc.Ems.Tags;
using Aulac.Global.Enums; using Aulac.Global.Data; using Aulac.Global.Common; using Aulac.Global.Xml;
using Aulac.Srv.Db.Common;
using Aulac.Srv.Db.Data.Ems.MdcFiles.Pnts;
namespace Aulac.Srv.Db.Data.Ems.MdcFiles
{

    public partial class MdcFilePntMng : Ems.Common.DbEmsDataManager, IMdcFilePntMng
	{
        public MdcFilePntMng(IDbAulacConnect pDb)
            : base(pDb)
		{
        }


        #region Public Methods
        public string SetMdcFilePntExam(XmlDataDocument xmlMdcFiles)
        {
            PntInfoPrvd pnt = new PntInfoPrvd(DbDataProvider);
            pnt.SetPntInfo(xmlMdcFiles);

            XmlElement  eMdcFile = XmlProcess.GetVchHeaderElm(xmlMdcFiles);
            string sMdcFilePrkID = XmlProcess.GetValueAtrb(eMdcFile, tagMdcFiles.MdcFiles.MdcFilePrkID);
            if (ValueHelper.isEmpty(sMdcFilePrkID))
                sMdcFilePrkID = AddMdcFilesPntExam(eMdcFile);
            else
                 UpdateMdcFilesExam(eMdcFile);
            
            return sMdcFilePrkID;
        }
        
        public bool DelMdcFilePnt(string pPntPrkID, string pHspInNum)
        {
            //Code: 02/21/2011 by Thangnc */
            return DelMdcFilePntDb(pPntPrkID, pHspInNum);
        }
        
        public XmlDataDocument FindPntToRegExam(XmlDataDocument xmlParam)
        {
            PntInfoPrvd pntInfo = new PntInfoPrvd(this.DbDataProvider);
            return pntInfo.FindPntToRegExam(xmlParam);
        }
 
        #endregion
       
        private string AddMdcFilesPntExam(XmlElement ePntInfo)
        {

            return ExecQueryMdcFilePntDb(ePntInfo, QueryCmdTypes.AddDataTable);

            /*string[] arr = mListMdcExam.GetRange(1, mListMdcExam.Count - 1).ToArray();
            sqlQuery = SqlHelper.CreateSqlInsert(TableNames.MdcFile_PntExam, arr);

            DbDataProvider.AddParamToCmd(mDbCmd, ePntInfo, arr);
            if (DbDataProvider.ExecuteNonQuery(ref mDbCmd, sqlQuery) > 0)
            {
                XmlProcess.SetAtrb(ref ePntInfo, tagMdcFiles.Pnt.MdcFilePrkID, DbDataProvider.SelectMaxIdentityID(mDbCmd, TableNames.MdcFile_PntExam, tagMdcFiles.Pnt.MdcFilePrkID));
                return true;
            }
            else return false;
             */ 
        }

        private void UpdateMdcFilesExam(XmlElement ePntInfo)
        {
            ExecQueryMdcFilePntDb(ePntInfo, QueryCmdTypes.UpdateDataTable);

            /*string sMdcFilesPnt = XmlProcess.GetValueAtrb(ePntInfo, tagMdcFiles.MdcFiles.MdcFilePrkID);

            string[] arr = ClsMdcFileHelper.mListMdcFileH.GetRange(1, ClsMdcFileHelper.mListMdcFileH.Count - 1).ToArray();

            sqlQuery = SqlHelper.CreateSqlUpdate(TableNames.MdcFile_PntExam, arr);
            sqlQuery += string.Format(" WHERE ({0} = ?) ", tagMdcFiles.MdcFiles.MdcFilePrkID);
            
            DbDataProvider.AddParamToCmd( mDbCmd, ePntInfo, arr);
            DbDataProvider.AddParamToCmd(mDbCmd, false, sMdcFilesPnt);
            return DbDataProvider.ExecuteNonQuery(ref mDbCmd, sqlQuery) > 0;
             */ 
        }

      
    }
}
